package com.example.zhinongbao.view;

import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.example.zhinongbao.R;
import com.example.zhinongbao.adapter.ProductListAdapter;
import com.example.zhinongbao.entity.ProductInfo;

import java.util.ArrayList;
import java.util.List;

public class ProductActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private List<ProductInfo> mProductInfoList = new ArrayList<>();
    private ProductListAdapter productListAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_tab_shop);
        //初始化控件
        recyclerView = findViewById(R.id.recyclerView);
        //模拟数据
        mProductInfoList.add(new ProductInfo(0,R.drawable.mogu1,"自然牛肝菌","菌类","一斤","180"));
        mProductInfoList.add(new ProductInfo(0,R.drawable.pinggu,"自然生长的平菇","菌类","一斤","100"));
        mProductInfoList.add(new ProductInfo(0,R.drawable.zhenmo,"自然生长的榛蘑","菌类","一斤","200"));
        mProductInfoList.add(new ProductInfo(0,R.drawable.dasuan,"农家土地种的大蒜","蔬菜","一斤","12"));
        mProductInfoList.add(new ProductInfo(0,R.drawable.doujiao,"农家土地种的豆角","蔬菜","一斤","10"));
        mProductInfoList.add(new ProductInfo(0,R.drawable.fengmi,"农家的好蜂蜜","农产品","一斤","50"));
        mProductInfoList.add(new ProductInfo(0,R.drawable.jidan,"溜达鸡下的土鸡蛋","韩版","一斤","10"));
        mProductInfoList.add(new ProductInfo(0,R.drawable.kugua,"农家土地种的苦瓜","蔬菜","一斤","7"));
        mProductInfoList.add(new ProductInfo(0,R.drawable.lajiao,"农家土地种的辣椒","蔬菜","一斤","8"));
        mProductInfoList.add(new ProductInfo(0,R.drawable.tudou,"农家土地种的土豆","蔬菜","一斤","3"));
        mProductInfoList.add(new ProductInfo(0,R.drawable.zishu,"农家土地种的紫薯","蔬菜","一斤","4"));
        mProductInfoList.add(new ProductInfo(0,R.drawable.huluobo,"农家土地种的胡萝卜","蔬菜","一斤","5"));

        //创建适配器
        productListAdapter = new ProductListAdapter(mProductInfoList);
        //设置适配器
        recyclerView.setAdapter(productListAdapter);
        //如果不在xml中设置app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"，就需要在代码中设置
//        recyclerView.setLayoutManager(new LinearLayoutManager(ProductActivity.this));
        //recyclerView列表的点击事件

    }
}
